python get current file location

86

python get current file location -

import os
os.path.dirname(os.path.abspath(__file__))

get current file name python -

import os
os.path.basename(__file__)

python get file extension from path -

import os.path
extension = os.path.splitext(filename)[1]

python get path of current file -

import pathlib
pathlib.Path(__file__).parent.absolute()

Comments

Submit
0 Comments